package dao;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.Query;

import model.Prova;

public class ProvaDAO {

    private EntityManager em;
	
	public ProvaDAO(EntityManager em){
		this.em = em;
	}
	
	public void adicionarProvaDAO(Prova p){
		p.setTipo(em.merge(p.getTipo()));
		em.merge(p);
	}
	public void remove(Prova p) {
		Prova p1 = em.merge(p);
		em.remove(p1);		
	}
	public List<Prova> listar() {
		Query q = em.createQuery("select u from Prova u");
		return q.getResultList();
	}

	public Prova buscar(Long id) {
		Query q = em.createQuery("select u from Prova u where u.id = :id");
		q.setParameter("id", id);		
		return (Prova) q.getSingleResult();
	}
}
